/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('ecs-workbench', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetInstanceRecordConfigRequest {
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='i-xxx'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
}

model GetInstanceRecordConfigResponseBody = {
  code?: string(name='Code', example='InvalidParamter'),
  message?: string(name='Message', example='Parameter is null or invalid.'),
  requestId?: string(name='RequestId', example='473469C7-AA6F-4DC5-B3DB-A3DC0DE3****'),
  root?: {
    expirationDays?: int32(name='ExpirationDays', example='7'),
    instanceId?: string(name='InstanceId', example='i-xxxx'),
    parentId?: string(name='ParentId', example='123'),
    recordStorageTarget?: string(name='RecordStorageTarget', example='acs:oss:cn-shanghai:123:workbench-record-123-1/record'),
  }(name='Root'),
  success?: boolean(name='Success', example='true'),
}

model GetInstanceRecordConfigResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetInstanceRecordConfigResponseBody(name='body'),
}

/**
 * @summary 获取实例录屏配置
 *
 * @param request GetInstanceRecordConfigRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetInstanceRecordConfigResponse
 */
async function getInstanceRecordConfigWithOptions(request: GetInstanceRecordConfigRequest, runtime: Util.RuntimeOptions): GetInstanceRecordConfigResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetInstanceRecordConfig',
    version = '2022-02-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 获取实例录屏配置
 *
 * @param request GetInstanceRecordConfigRequest
 * @return GetInstanceRecordConfigResponse
 */
async function getInstanceRecordConfig(request: GetInstanceRecordConfigRequest): GetInstanceRecordConfigResponse {
  var runtime = new Util.RuntimeOptions{};
  return getInstanceRecordConfigWithOptions(request, runtime);
}

model ListInstanceRecordsRequest {
  instanceId?: string(name='InstanceId', example='i-xxx'),
  pageNumber?: int32(name='PageNumber'),
  pageSize?: int32(name='PageSize'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
}

model ListInstanceRecordsResponseBody = {
  code?: string(name='Code', example='InvalidParamter'),
  message?: string(name='Message', example='Parameter is null or invalid.'),
  requestId?: string(name='RequestId', example='473469C7-AA6F-4DC5-B3DB-A3DC0DE3****'),
  root?: {
    recordList?: [ 
      {
        accountId?: long(name='AccountId', example='1234'),
        expireTime?: string(name='ExpireTime', example='2023-11-16T02:59:39Z'),
        gmtCreate?: string(name='GmtCreate', example='2023-04-10T12:41:28Z'),
        instanceId?: string(name='InstanceId', example='i-xxxx'),
        instanceRecordUrl?: string(name='InstanceRecordUrl', example='https://ecs-workbench.aliyun.com/view/instance/record/replay/abc'),
        recordDurationMillis?: long(name='RecordDurationMillis', example='123'),
        status?: string(name='Status', example='running'),
        terminalSessionToken?: string(name='TerminalSessionToken', example='abc'),
      }
    ](name='RecordList'),
    totalCount?: int32(name='TotalCount', example='15'),
  }(name='Root'),
  success?: boolean(name='Success', example='true'),
}

model ListInstanceRecordsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListInstanceRecordsResponseBody(name='body'),
}

/**
 * @summary 获取实例录屏记录列表
 *
 * @param request ListInstanceRecordsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListInstanceRecordsResponse
 */
async function listInstanceRecordsWithOptions(request: ListInstanceRecordsRequest, runtime: Util.RuntimeOptions): ListInstanceRecordsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.pageNumber)) {
    body['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    body['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ListInstanceRecords',
    version = '2022-02-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 获取实例录屏记录列表
 *
 * @param request ListInstanceRecordsRequest
 * @return ListInstanceRecordsResponse
 */
async function listInstanceRecords(request: ListInstanceRecordsRequest): ListInstanceRecordsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listInstanceRecordsWithOptions(request, runtime);
}

model ListTerminalCommandsRequest {
  pageNumber?: int32(name='PageNumber', example='1'),
  pageSize?: int32(name='PageSize', example='10'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
  terminalSessionToken?: string(name='TerminalSessionToken', description='This parameter is required.', example='abc'),
}

model ListTerminalCommandsResponseBody = {
  pageNumber?: int32(name='PageNumber', example='10'),
  pageSize?: int32(name='PageSize', example='1'),
  requestId?: string(name='RequestId', example='473469C7-AA6F-4DC5-B3DB-A3DC0DE3****'),
  terminalCommandList?: [ 
    {
      commandLine?: string(name='CommandLine', example='ls'),
      createTime?: string(name='CreateTime', example='2024-04-16T03:53:18Z'),
      executePath?: string(name='ExecutePath', example='/root'),
      loginUser?: string(name='LoginUser', example='root'),
    }
  ](name='TerminalCommandList'),
  totalCount?: int32(name='TotalCount', example='3'),
}

model ListTerminalCommandsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListTerminalCommandsResponseBody(name='body'),
}

/**
 * @summary 查看实例Workbench登录后执行命令的历史列表。
 *
 * @param request ListTerminalCommandsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListTerminalCommandsResponse
 */
async function listTerminalCommandsWithOptions(request: ListTerminalCommandsRequest, runtime: Util.RuntimeOptions): ListTerminalCommandsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.pageNumber)) {
    body['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    body['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.terminalSessionToken)) {
    body['TerminalSessionToken'] = request.terminalSessionToken;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ListTerminalCommands',
    version = '2022-02-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 查看实例Workbench登录后执行命令的历史列表。
 *
 * @param request ListTerminalCommandsRequest
 * @return ListTerminalCommandsResponse
 */
async function listTerminalCommands(request: ListTerminalCommandsRequest): ListTerminalCommandsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listTerminalCommandsWithOptions(request, runtime);
}

model LoginInstanceRequest {
  instanceLoginInfo?: {
    authenticationType?: string(name='AuthenticationType', example='password/certificate'),
    certificate?: string(name='Certificate', example='----begin----
----end----'),
    credentialToken?: string(name='CredentialToken'),
    dockerContainerName?: string(name='DockerContainerName'),
    dockerExec?: string(name='DockerExec'),
    durationSeconds?: long(name='DurationSeconds', example='123'),
    expireTime?: string(name='ExpireTime', example='2022-11-30 00:00:00'),
    host?: string(name='Host', example='127.0.0.1'),
    instanceId?: string(name='InstanceId', example='i-123'),
    instanceType?: string(name='InstanceType', example='ecs/eci/ack'),
    loginByInstanceCredential?: boolean(name='LoginByInstanceCredential'),
    loginByInstanceShortcut?: boolean(name='LoginByInstanceShortcut'),
    networkAccessMode?: string(name='NetworkAccessMode', example='vpc/classic'),
    options?: {
      audioMuteSeconds?: int32(name='AudioMuteSeconds'),
      containerInfo?: {
        clusterId?: string(name='ClusterId', example='abcdef'),
        clusterName?: string(name='ClusterName', example='abc'),
        containerName?: string(name='ContainerName', example='abc'),
        deployment?: string(name='Deployment', example='abc'),
        endpoint?: string(name='Endpoint', example='abc'),
        headers?: map[string]any(name='Headers', example='{"abc":"def"}'),
        namespace?: string(name='Namespace', example='abc'),
        podName?: string(name='PodName', example='abc'),
      }(name='ContainerInfo'),
      fixedHeight?: int32(name='FixedHeight'),
      fixedWidth?: int32(name='FixedWidth'),
      notificationEventTypes?: string(name='NotificationEventTypes', example='abc'),
      notificationRecipientUrl?: string(name='NotificationRecipientUrl', example='abc'),
      notificationRetryIntervalSeconds?: int32(name='NotificationRetryIntervalSeconds', example='10'),
      notificationRetryLimit?: int32(name='NotificationRetryLimit', example='3'),
      operationDisableSeconds?: int32(name='OperationDisableSeconds'),
      sessionControl?: string(name='SessionControl', example='abc'),
      videoFreezeSeconds?: int32(name='VideoFreezeSeconds'),
    }(name='Options'),
    passPhrase?: string(name='PassPhrase', example='xxxx'),
    password?: string(name='Password', example='xxxxx'),
    port?: int32(name='Port', example='22/3389'),
    protocol?: string(name='Protocol', example='ssh/rdp/ack'),
    regionId?: string(name='RegionId', example='cn-hangzhou/cn-beijing'),
    resourceGroupId?: string(name='ResourceGroupId'),
    shortcutToken?: string(name='ShortcutToken'),
    username?: string(name='Username', example='root/Administrator'),
    vpcId?: string(name='VpcId', example='vpc-abc'),
  }(name='InstanceLoginInfo'),
  partnerInfo?: {
    partnerId?: string(name='PartnerId', example='abc'),
    partnerName?: string(name='PartnerName', example='abc'),
  }(name='PartnerInfo'),
  userAccount?: {
    accountId?: long(name='AccountId', example='1234'),
    accountPlatform?: string(name='AccountPlatform', example='aas'),
    accountStructure?: string(name='AccountStructure', example='2/3/4'),
    durationSeconds?: long(name='DurationSeconds', example='100'),
    empId?: string(name='EmpId', example='123abc'),
    expireTime?: string(name='ExpireTime', example='2022-11-30 00:00:00'),
    loginName?: string(name='LoginName', example='abc'),
    options?: {
      loginLimit?: long(name='LoginLimit', example='3'),
    }(name='Options'),
    parentId?: long(name='ParentId', example='1234'),
  }(name='UserAccount'),
}

model LoginInstanceResponseBody = {
  code?: string(name='Code', example='InvalidParamter'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', description='Id of the request', example='abc-123'),
  root?: {
    disposableAccount?: {
      loginFormActionUrl?: string(name='LoginFormActionUrl', example='abc'),
      loginUrl?: string(name='LoginUrl', example='abc'),
    }(name='DisposableAccount'),
    instanceLoginInfoList?: [ 
      {
        instanceId?: string(name='InstanceId', example='i-abc'),
        instanceLoginToken?: string(name='InstanceLoginToken', example='134'),
        instanceLoginView?: {
          defaultViewUrl?: string(name='DefaultViewUrl', example='abc'),
        }(name='InstanceLoginView'),
        loginSuccess?: boolean(name='LoginSuccess', example='true'),
      }
    ](name='InstanceLoginInfoList'),
    sessionControl?: {
      baseUrl?: string(name='BaseUrl', example='abc'),
    }(name='SessionControl'),
  }(name='Root'),
  success?: string(name='Success', example='true/false'),
}

model LoginInstanceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: LoginInstanceResponseBody(name='body'),
}

/**
 * @summary 登录实例
 *
 * @param request LoginInstanceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return LoginInstanceResponse
 */
async function loginInstanceWithOptions(request: LoginInstanceRequest, runtime: Util.RuntimeOptions): LoginInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceLoginInfo)) {
    query['InstanceLoginInfo'] = request.instanceLoginInfo;
  }
  if (!Util.isUnset(request.partnerInfo)) {
    query['PartnerInfo'] = request.partnerInfo;
  }
  if (!Util.isUnset(request.userAccount)) {
    query['UserAccount'] = request.userAccount;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'LoginInstance',
    version = '2022-02-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 登录实例
 *
 * @param request LoginInstanceRequest
 * @return LoginInstanceResponse
 */
async function loginInstance(request: LoginInstanceRequest): LoginInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return loginInstanceWithOptions(request, runtime);
}

model SetInstanceRecordConfigRequest {
  enabled?: boolean(name='Enabled', description='This parameter is required.', example='true'),
  expirationDays?: int32(name='ExpirationDays', example='7'),
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='i-xxx'),
  recordStorageTarget?: string(name='RecordStorageTarget', example='acs:oss:cn-shanghai:123:workbench-record-123-1/record'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
}

model SetInstanceRecordConfigResponseBody = {
  code?: string(name='Code', example='InvalidParamter'),
  message?: string(name='Message', example='Parameter is null or invalid.'),
  requestId?: string(name='RequestId', example='473469C7-AA6F-4DC5-B3DB-A3DC0DE3****'),
  root?: boolean(name='Root', example='true'),
  success?: boolean(name='Success', example='true'),
}

model SetInstanceRecordConfigResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SetInstanceRecordConfigResponseBody(name='body'),
}

/**
 * @summary 设置实例录屏配置
 *
 * @param request SetInstanceRecordConfigRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SetInstanceRecordConfigResponse
 */
async function setInstanceRecordConfigWithOptions(request: SetInstanceRecordConfigRequest, runtime: Util.RuntimeOptions): SetInstanceRecordConfigResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.enabled)) {
    body['Enabled'] = request.enabled;
  }
  if (!Util.isUnset(request.expirationDays)) {
    body['ExpirationDays'] = request.expirationDays;
  }
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.recordStorageTarget)) {
    body['RecordStorageTarget'] = request.recordStorageTarget;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SetInstanceRecordConfig',
    version = '2022-02-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 设置实例录屏配置
 *
 * @param request SetInstanceRecordConfigRequest
 * @return SetInstanceRecordConfigResponse
 */
async function setInstanceRecordConfig(request: SetInstanceRecordConfigRequest): SetInstanceRecordConfigResponse {
  var runtime = new Util.RuntimeOptions{};
  return setInstanceRecordConfigWithOptions(request, runtime);
}

model ViewInstanceRecordsRequest {
  instanceId?: string(name='InstanceId', description='This parameter is required.', example='i-123'),
  regionId?: string(name='RegionId', example='cn-hangzhou'),
  terminalSessionToken?: string(name='TerminalSessionToken', description='This parameter is required.', example='abc'),
}

model ViewInstanceRecordsResponseBody = {
  code?: string(name='Code', example='InvalidParamter'),
  message?: string(name='Message', example='Parameter is null or invalid.'),
  requestId?: string(name='RequestId', example='473469C7-AA6F-4DC5-B3DB-A3DC0DE3****'),
  root?: boolean(name='Root', example='true'),
  success?: boolean(name='Success', example='true'),
}

model ViewInstanceRecordsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ViewInstanceRecordsResponseBody(name='body'),
}

/**
 * @summary 查看实例录屏内容
 *
 * @param request ViewInstanceRecordsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ViewInstanceRecordsResponse
 */
async function viewInstanceRecordsWithOptions(request: ViewInstanceRecordsRequest, runtime: Util.RuntimeOptions): ViewInstanceRecordsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  if (!Util.isUnset(request.regionId)) {
    body['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.terminalSessionToken)) {
    body['TerminalSessionToken'] = request.terminalSessionToken;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ViewInstanceRecords',
    version = '2022-02-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 查看实例录屏内容
 *
 * @param request ViewInstanceRecordsRequest
 * @return ViewInstanceRecordsResponse
 */
async function viewInstanceRecords(request: ViewInstanceRecordsRequest): ViewInstanceRecordsResponse {
  var runtime = new Util.RuntimeOptions{};
  return viewInstanceRecordsWithOptions(request, runtime);
}

